///\todo upgrade

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_ZZ_AUTO_FUNCTIONS_H_
#define _BUOLA_ZZ_AUTO_FUNCTIONS_H_

namespace buola { namespace zz {

template<typename tIt,typename tExpr,typename tAttr>
bool parse(tIt &pB,const tIt &pE,const tExpr &pExpr,tAttr &pAttr)
{
    int lCtx;
    return pExpr.Parse(pB,pE,pAttr,lCtx,UUnused());
}

template<typename tIt,typename tExpr>
bool parse(tIt &pB,const tIt &pE,const tExpr &pExpr)
{
    UUnused lAttr;
    return parse(pB,pE,pExpr,lAttr);
}

template<typename tIt,typename tExpr,typename tAttr>
bool parse(const tIt &pB,const tIt &pE,const tExpr &pExpr,tAttr &pAttr)
{
    int lCtx;
    tIt lI=pB;
    return pExpr.Parse(lI,pE,pAttr,lCtx,UUnused());
}

template<typename tIt,typename tExpr>
bool parse(const tIt &pB,const tIt &pE,const tExpr &pExpr)
{
    UUnused lAttr;
    tIt lI=pB;
    return parse(lI,pE,pExpr,lAttr);
}

template<typename tIt,typename tExpr,typename tSk,typename tAttr>
bool phrase_parse(tIt &pB,const tIt &pE,const tExpr &pExpr,const tSk &pSk,tAttr &&pAttr)
{
    int lCtx;
    if(pExpr.Parse(pB,pE,pAttr,lCtx,pSk))
    {
        //post skip]
        skip_over(pB,pE,pSk);
        return true;
    }
    return false;
}

template<typename tIt,typename tExpr,typename tSk>
bool phrase_parse(tIt &pB,const tIt &pE,const tExpr &pExpr,const tSk &pSk)
{
    UUnused lAttr;
    return phrase_parse(pB,pE,pExpr,pSk,lAttr);
}

template<typename tIt,typename tExpr,typename tSk,typename tAttr>
bool phrase_parse(const tIt &pB,const tIt &pE,const tExpr &pExpr,const tSk &pSk,tAttr &&pAttr)
{
    int lCtx;
    tIt lB=pB;
    //no post skip needed, since the iterator is discarded
    return pExpr.Parse(lB,pE,pAttr,lCtx,pSk);
}

template<typename tIt,typename tExpr,typename tSk>
bool phrase_parse(const tIt &pB,const tIt &pE,const tExpr &pExpr,const tSk &pSk)
{
    UUnused lAttr;
    return phrase_parse(pB,pE,pExpr,pSk,lAttr);
}

template<typename tIt>
inline void skip_over(tIt& /*pB*/,const tIt& /*pE*/,const UUnused&)
{
}

template<typename tIt,typename tSk>
inline void skip_over(tIt& /*pB*/,const tIt& /*pE*/,const detail::CSkipDisabler<tSk>&)
{
}

template<typename tIt,typename tSk>
inline void skip_over(tIt &pB,const tIt &pE,const tSk &pSk)
{
    UUnused lDummy1,lDummy2,lDummy3;
    while(pSk.Parse(pB,pE,lDummy1,lDummy2,lDummy3)) {}
}

/*namespace zz*/ } /*namespace buola*/ }

#endif
